public class InsertSort {
    public static void main(String[] args) {
        int[] arr = { 5, 2, 4, 6, 1, 3 };
        System.out.println("Before sorting: " + java.util.Arrays.toString(arr));
        insertSort(arr);
        System.out.println("After sorting: " + java.util.Arrays.toString(arr));
    }

    public static void insertSort(int[] arr) {
        int n = arr.length;
        int i, j, temp;
        for (i = 1; i < n; i++) {
            temp = arr[i];
            j = i - 1;
            while (j >= 0 && arr[j] > temp) {
                arr[j + 1] = arr[j];
                j--;
            }
            arr[j + 1] = temp;
        }
    }
}
